#include<stdio.h>
#include<string.h>
//先逆置k个字符，再把剩余字符逆置，最后整体逆置

void Swap(char *p1,char *p2)
{
  char tmp = *p1;
  *p1 = *p2;
  *p2 = tmp;
}

void rotate(char *str,int k)
{
  int len = strlen(str);
  char *p1 = str;
  char *p2 =str + k%len-1;
  char *p3 = p2+1;
  char *p4 = str+len-1;
  while(p1<=p2)
  {
    Swap(p1,p2);
    p1++;
    p2--;
  }

  while(p3<=p4)
  {
    Swap(p3,p4);
    p3++;
    p4--;
  }

  p1 = str;
  p4 = str+len-1;

  while(p1<=p4)
  {
    Swap(p1,p4);
    p1++;
    p4--;
  }
  
}


int main()
{
  char str[] = "1234abcdef";
  int k = 21;
  printf("%s\n",str);
  rotate(str,k);
  printf("%s\n",str);
  return 0;
}
